import sys

def usage():
	print "Usage:\n%s simulation-data-filename" % (sys.argv[0])
	
def check_args():
	if len(sys.argv)<2:
		return False
	else:
		return True



		
		
if __name__=="__main__":

	if not check_args():
		usage()
		exit()
	
	try:
		import matplotlib.pyplot as plt
	except:
		print "Error: Could not find the matplotlib library on your system."
		print "Please install the matplotlib library for python first:"
		print "\tsudo apt-get install python-matplotlib"
		exit()	
		
	filename=sys.argv[1]
	
	try:
		f=open(filename,"r")
		print "Opened file %s for reading" % (filename)
	except:
		print "Error: Could not open the file."
		exit()
	#////////////////////////////////////////////////////////
	
	# EXTRACT DATA
	
	labels=[]
	data=[]	
	lab=True
	
	for line in f:
		if lab:
			labels=line.split("\t")
			labels.remove("\n")
			lab=False
		else:
			line=line.split("\t")
			line.remove("\n")
			data.append([ int(x) for x in line])	
		
	rounds=[x[0] for x in data]
	populations=[]
	
	for i in range(1,len(labels)):
		tmp=[x[i] for x in data]
		populations.append(tmp)
			
	# PLOT DATA

    	

    	
	for pop in populations:	
		plt.plot(rounds,pop)
	
	plt.title("Agent population=f(time)")
	plt.xlabel("t (round)")
    	plt.ylabel("Number of agents")
	
	labels.remove("round")
    	plt.legend(tuple(labels),'best')
    	
	plt.show()
	
	#////////////////////////////////////////////////////////	
	f.close()
		
		
		
		
		
	
	
